#ifndef TIMERTICKANIMATOR_H
#define TIMERTICKANIMATOR_H

#include "Animator.h"
#include "TickAnimation.h"
#include "Timer.h"

class TimerTickAnimator : public Animator {
private:
	TickAnimation *tickAnim;
	unsigned int timeTicks;
public:	
	void Start(timestamp_t t) {
		lastTime = t;
		state = ANIMATOR_RUNNING;
	};

	void Progress(timestamp_t currTime) {
		if (currTime > lastTime && currTime - lastTime >= tickAnim->GetDelay()) {
			lastTime += tickAnim->GetDelay();
			tickAnim->ExecuteAction();
			++timeTicks;
			if((tickAnim->GetRepetitions()!=0) && (timeTicks == tickAnim->GetRepetitions())) {
				state = ANIMATOR_FINISHED;
				NotifyStopped();
				return;
			}
		}
	};

	TimerTickAnimator (TickAnimation* tick) {
		tickAnim = tick;
		timeTicks = 0;
	};

	~TimerTickAnimator(void) {}
};

#endif